﻿package com.gzc.pm.servlet;

import java.io.File;
import java.io.IOException;
import java.net.URLEncoder;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.skyclass.io.SitePathInfo;
import cn.skyclass.servlet.FileDownloadServlet;

public class MeasureAnalyseExcelDownload extends FileDownloadServlet {

	
	private static final long serialVersionUID = 8845857642403092057L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html");
		ServletOutputStream out = response.getOutputStream();

		String fileName = "MeasureDataTemplate.xls";
		String filePath = SitePathInfo.getInstance().getWebDataPath()+"template/"+fileName;

		File file = new File(filePath);
		if (!file.exists()) {
			logger.info("文件不存在! path:" + file.getAbsolutePath());
		} else {
			this.responseFile(response, request, fileName, filePath);
		}

		out.close();
		
	}
	
	protected void responseFile(HttpServletResponse response, HttpServletRequest request, String fileName, String filePath) throws IOException, ServletException{
		String agent = request.getHeader("USER-AGENT");
		if(null != agent && -1 != agent.indexOf("MSIE")){
			fileName = URLEncoder.encode(fileName, "utf-8");
		}else if(null != agent && -1 != agent.indexOf("Mozilla")){
			fileName = new String(fileName.getBytes("utf-8"), "ISO8859_1");
		}
		
		super.responseFile(response, fileName, filePath);
		
	}

}
